package com.cysyz.mylib.excel;

import java.util.ArrayList;
import java.util.List;

import com.cysyz.mylib.excel.validator.CellValueValidator;

public class SheetHeader {
	private String headerName;
	private List<CellValueValidator> cellValueValidators = new ArrayList<CellValueValidator>();
	
	public SheetHeader(String headerName, List<CellValueValidator> cellValueValidators) {
		super();
		this.headerName = headerName;
		this.cellValueValidators = cellValueValidators;
	}
	
	public SheetHeader(String headerName) {
		this.headerName = headerName;
	}
	
	public String getHeaderName() {
		return headerName;
	}
	public void setHeaderName(String headerName) {
		this.headerName = headerName;
	}
	public List<CellValueValidator> getCellValueValidator() {
		return cellValueValidators;
	}
	public void setCellValueValidator(List<CellValueValidator> cellValueValidators) {
		this.cellValueValidators = cellValueValidators;
	}
	
	public void addCellValueValidator(CellValueValidator cellValueValidator) {
		cellValueValidators.add(cellValueValidator);
	}
	
	/**
	 * 校验标题对应的某个cell中的值
	 * @Title: validateCell
	 * @Author: 崔勇
	 * @Date 2014-4-23 下午2:42:20
	 * @param cell cell中的内容
	 * @param rowNum 行号
	 * @param colNum 列号
	 * @return 如果没有问题返回null，否则返回错误信息
	 */
	public String validateCell(String cell, int rowNum, int colNum) {
		String errorMessage = null;
		for (CellValueValidator cellValueValidator : this.cellValueValidators) {
			errorMessage = cellValueValidator.validateCell(this.headerName, cell, rowNum, colNum);
			if (errorMessage != null) {
				return errorMessage;
			}
		}
		return null;
	}
	
}
